/*
  S.M.A.C.K - An operating system kernel
  Copyright (C) 2010,2011 Mattias Holm and Kristian Rietveld
  For licensing and a full list of authors of the kernel, see the files
  COPYING and AUTHORS.
*/

#ifndef KERNEL_TIMER_H
#define KERNEL_TIMER_H

#include <stdint.h>

#define CLOCK_RATE (1/100)  /* Interrupt period in seconds */
#define CLOCK_RATE_MS 10    /* Interrupt period in ms ((1 / 100) * 1000) */

#define GPT1_IRQ 37

/* The following functions need an architecture-dependent implementation: */

void hw_timer_init(void);
uint32_t timer_get_system_ticks(void);

void msleep(int msec);

/* The following functions are common for all platforms: */

typedef void (* timeout_func_t) (void *data);

struct timer_entry_t
{
  uint32_t deadline;
  timeout_func_t func;
  void *func_data;
};

void timer_init(void);

void timer_call_handler(void);
void timer_register_timeout(uint32_t        timeout,
                            timeout_func_t  func,
                            void           *func_data);
void timer_deregister_timeout(timeout_func_t  func,
                              void           *func_data);

#endif /* ! KERNEL_TIMER_H */
